package fun.sanguo.model.dto;

import lombok.Data;

import java.util.List;

/**
 * 页面信息
 *
 * @author ZYP
 * @date 2022-04-26
 */
@Data
public class PageInfo<T> extends ResponseDto {

    /**
     * 数据列表
     */
    private List<T> list;

    /**
     * 数据量
     */
    private int total;

    /**
     * 分页信息
     */
    private int pageNum;
    private int pageSize;

    /**
     * 排序信息
     */
    private String sortField;
    private String sortOrder;

    public PageInfo(List<T> list, int total, PageQuery pageQuery) {
        // 默认初始化
        this.list = list;
        this.total = total;
        this.pageNum = pageQuery.getPageNum();
        this.pageSize = pageQuery.getPageSize();
        this.sortField = pageQuery.getSortField();
        this.sortOrder = pageQuery.getSortOrder();
        // 异常处理，总量为零时跳转第一页
        if (total == 0) {
            this.pageNum = 1;
        }
    }
}
